Skip to main content

📉 Schema Migration Analysis

TL;DR

Metis can scan your pull requests for changes in your database schema, analyze those changes and show you insights about them.

How it works

The SQL commands used for changing the schema of the databases are usually stored in a folder.

note

ORMs manages the SQL commands in a folder, usually with a subfolder for each version.

The GitHub Action review all the migration SQL commands and sends them to Metis, which analyze them and warn about the impact on the database.

Prerequisites

A Metis account with a valid API key. 🥽 Create a project & generate API key

Installation

On code with ORMs that generates SQL files:

Link to the action in GitHub marketplace

Add the following code to your GitHub Actions workflow file:

- name: Analyze migrations
uses: metis-data/sql-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>

Parameters

Github workflow example

on:
pull_request:
types: [opened, reopened, edited, synchronize, ready_for_review]

jobs:
migrations:
name: Analyze new migrations
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Compare migrations
uses: metis-data/sql-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>

On JS code with Sequelize ORM:

Link to the action in GitHub marketplace

caution

Please use standard Sequelize migrations files that generated by Sequelize CLI and exports up/down functions from module.

Add the following code to your GitHub Actions workflow file:

- name: Analyze migrations
uses: metis-data/sequelize-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>
migrations_dir: <path/to/migrations/directory>

Parameters

  • from - Base sha to be compared
  • to - Branch sha to be compared with
  • github_token - Auto generated workflow GitHub token
  • metis_api_key - Metis Api Key generated at Metis
  • migrations_dir - Path in your project to Sequelize migrations directory

Github workflow example

on:
pull_request:
types: [opened, reopened, edited, synchronize, ready_for_review]

jobs:
migrations:
name: Analyze new migrations
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Compare migrations
uses: metis-data/sql-migrations-validator@v1
with:
from: ${{ github.event.pull_request.base.sha }}
to: ${{ github.event.pull_request.head.sha }}
github_token: ${{ github.token }}
metis_api_key: <Your Api Key>
migrations_dir: migrations